package com.csun.cmny.provider.service.impl;

import com.csun.cmny.base.dto.LoginAuthDto;
import com.csun.cmny.base.enums.ErrorCodeEnum;
import com.csun.cmny.core.support.BaseService;
import com.csun.cmny.provider.constant.Constant;
import com.csun.cmny.provider.dao.OmcMedicPlanMapper;
import com.csun.cmny.provider.dao.OmcMedicRecordMapper;
import com.csun.cmny.provider.dao.OmcNursingRoomBindMapper;
import com.csun.cmny.provider.exceptions.OmcBizException;
import com.csun.cmny.provider.model.constant.MedicConstant;
import com.csun.cmny.provider.model.domain.OmcMedicPlan;
import com.csun.cmny.provider.model.domain.OmcMedicRecord;
import com.csun.cmny.provider.model.domain.OmcNursingRoomBind;
import com.csun.cmny.provider.model.domain.OmcOrder;
import com.csun.cmny.provider.model.dto.medic.MedicPlanConfirmDto;
import com.csun.cmny.provider.model.dto.medic.MedicPlanDto;
import com.csun.cmny.provider.model.dto.medic.MedicPlanQueryDto;
import com.csun.cmny.provider.model.dto.medic.MedicPlanSignDto;
import com.csun.cmny.provider.model.vo.MedicPlanVo;
import com.csun.cmny.provider.model.vo.OldmanBedRoomBuildingVo;
import com.csun.cmny.provider.pojo.NursingGroup;
import com.csun.cmny.provider.resolver.CmnyMessageSource;
import com.csun.cmny.provider.service.*;
import com.csun.cmny.provider.vo.NursingGroupVo;
import com.csun.cmny.util.DateUtil;
import com.csun.cmny.util.PubUtils;
import com.csun.cmny.util.PublicUtil;
import com.github.pagehelper.PageHelper;
import com.google.common.base.Preconditions;
import lombok.extern.slf4j.Slf4j;
import org.activiti.engine.HistoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.impl.identity.Authentication;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Auther: chisj chisj@foxmal.com
 * @Date: 2019-08-13 15:10
 * @Description:
 */
@Slf4j
@Service
@Transactional
public class OmcMedicPlanServiceImpl extends BaseService<OmcMedicPlan>
        implements OmcMedicPlanService {

    @Resource
    private CmnyMessageSource cmnyMessageSource;
    @Resource
    private OmcMedicPlanMapper omcMedicPlanMapper;
    @Resource
    private OmcActivitiService omcActivitiService;
    @Resource
    private OmcGroupService omcGroupService;
    @Resource
    private TaskService taskService;
    @Resource
    private RuntimeService runtimeService;
    @Resource
    private HistoryService historyService;
    @Resource
    private OldmanService oldmanService;
    @Resource
    private OmcNursingRoomBindMapper omcNursingRoomBindMapper;
    @Resource
    private OmcMedicRecordService omcMedicRecordService;

    /**
     * query omc medic plan list with page
     *
     * @param medicPlanQueryDto the medic plan query dto
     * @return the list
     */
    @Override
    public List<OmcMedicPlan> queryListWithPage(MedicPlanQueryDto medicPlanQueryDto) {

        PageHelper.startPage(medicPlanQueryDto.getPageNum(), medicPlanQueryDto.getPageSize());

        return omcMedicPlanMapper.queryListWithPage(medicPlanQueryDto);
    }

    /**
     * medic plan apply
     *
     * @param medicPlanDto the medic plan dto
     * @param loginAuthDto the login auth dto
     * @return the int.
     */
    @Override
    public Integer apply(MedicPlanDto medicPlanDto, LoginAuthDto loginAuthDto) {

        OmcMedicPlan omcMedicPlan = new OmcMedicPlan();

        // 校验结束时间是否大于开始时间
        Preconditions.checkArgument(medicPlanDto.getEndDate()
                        .compareTo(medicPlanDto.getBeginDate()) >= 0,
                cmnyMessageSource.getMessage("medic.plan.end.compare.begin.date.error", null));

        // 获取用户是否为班长
        NursingGroup nursingGroup = new NursingGroup();
        nursingGroup.setUserId(loginAuthDto.getUserId());
        nursingGroup = omcGroupService.selectOne(nursingGroup);
        if (nursingGroup == null) {
            throw new OmcBizException(ErrorCodeEnum.OMC10038001);
        }
        omcMedicPlan.setNursingGroupId(nursingGroup.getId());

        // 判断老人是否为该班组
        OldmanBedRoomBuildingVo obrbv = oldmanService.queryOldmanBedRoomBuildingByOldmanId(
                medicPlanDto.getOldmanId().intValue());

        if (obrbv == null) {
            throw new OmcBizException(ErrorCodeEnum.OMC10038002);
        }

        // 校验老人是否为该班组
        OmcNursingRoomBind omcNursingRoomBind = new OmcNursingRoomBind();
        omcNursingRoomBind.setNursingGroupId(nursingGroup.getId());
        omcNursingRoomBind.setRoomId((long) obrbv.getRoomId());
        int count = omcNursingRoomBindMapper.selectCount(omcNursingRoomBind);
        if (count < 1) {
            // 该老人不属于该班组
            throw new OmcBizException(ErrorCodeEnum.OMC10038006);
        }

        omcMedicPlan.setOldmanName(obrbv.getOldmanName());

        // 启动流程
        Map<String, Object> variables = new HashMap<String, Object>();
        variables.put(MedicConstant.VAR_MEDIC_PLAN_USER_ID, loginAuthDto.getUserId().toString());

        ProcessInstance processInstance = omcActivitiService
                .startProcessInstanceByKeyAndTenantId(MedicConstant.PROCESS_KEY_MEDIC_PLAN,
                        variables, loginAuthDto.getGroupId());

        // 查询当前任务
        Task task = omcActivitiService.getTaskByProcessInstanceId(processInstance.getProcessInstanceId());

        // 添加批注
        omcActivitiService.addTaskComment(task, loginAuthDto.getUserName() + "[班长]", "提交申请");

        // 完成下单
        taskService.complete(task.getId());

        // 添加用药计划
        BeanUtils.copyProperties(medicPlanDto, omcMedicPlan);

        omcMedicPlan.setProcessInstanceId(processInstance.getProcessInstanceId());
        omcMedicPlan.setGroupId(loginAuthDto.getGroupId());
        omcMedicPlan.setUpdateInfo(loginAuthDto);
        omcMedicPlan.setState(MedicConstant.MEDIC_PLAN_STATE_APPLY);

        return omcMedicPlanMapper.insertSelective(omcMedicPlan);
    }

    /**
     * medic plan monitor confirm
     *
     * @param medicPlanConfirmDto the medic plan confirm dto
     * @param loginAuthDto        the login auth dto
     * @return the int.
     */
    @Override
    public Integer monitorConfirm(MedicPlanConfirmDto medicPlanConfirmDto, LoginAuthDto loginAuthDto) {

        Long userId = loginAuthDto.getUserId();

        // 查询用药计划
        OmcMedicPlan omcMedicPlanQuery = omcMedicPlanMapper.selectByPrimaryKey(medicPlanConfirmDto.getId());
        if (omcMedicPlanQuery == null) {
            // 用药计划不存在
            throw new OmcBizException(ErrorCodeEnum.OMC10038004);
        }

        // 提交计划者才可以确认
        if (!omcMedicPlanQuery.getCreatorId().equals(userId)) {
            // 无法确认
            throw new OmcBizException(ErrorCodeEnum.OMC10038005);
        }

        String processInstanceId = omcMedicPlanQuery.getProcessInstanceId();
        Task task = taskService.createTaskQuery()
                .taskTenantId(loginAuthDto.getGroupId().toString())
                .processDefinitionKey(MedicConstant.PROCESS_KEY_MEDIC_PLAN)
                .taskAssignee(userId.toString())
                .processInstanceId(processInstanceId)
                .taskDefinitionKey(MedicConstant.MEDIC_PLAN_TASK_CONFIRM)
                .singleResult();

        if (task == null) {
            // 任务不存在
            throw new OmcBizException(ErrorCodeEnum.OMC10038003);
        }

        String comment = MedicConstant.MEDIC_PLAN_COMMENT_REFUSE;
        Integer state = MedicConstant.MEDIC_PLAN_STATE_REFUSE;
        String msg = MedicConstant.VAR_MEDIC_PLAN_MSG_REFUSE;
        if (medicPlanConfirmDto.getState().equals(MedicConstant.MEDIC_PLAN_APRV_STATE_YES)) {
            msg = MedicConstant.VAR_MEDIC_PLAN_MSG_CONFIRM;
            state = MedicConstant.MEDIC_PLAN_STATE_CONFIRM;
            comment = MedicConstant.MEDIC_PLAN_COMMENT_CONFIRM;
        }
        taskService.setVariable(task.getId(), MedicConstant.VAR_MEDIC_PLAN_MSG, msg);

        // 设置用户id
        Authentication.setAuthenticatedUserId(loginAuthDto.getUserName() + "[班长]");
        // 添加批注信息
        taskService.addComment(task.getId(), processInstanceId, comment);
        // 完成任务
        taskService.complete(task.getId());

        OmcMedicPlan omcMedicPlan = new OmcMedicPlan();
        omcMedicPlan.setId(omcMedicPlanQuery.getId());
        omcMedicPlan.setUpdateInfo(loginAuthDto);
        omcMedicPlan.setState(state);

        return omcMedicPlanMapper.updateByPrimaryKeySelective(omcMedicPlan);
    }

    /**
     * medic plan family sign
     *
     * @param medicPlanSignDto the medic plan sign dto
     * @param loginAuthDto     the login auth dto
     * @return the int.
     */
    @Override
    public Integer familySign(MedicPlanSignDto medicPlanSignDto, LoginAuthDto loginAuthDto) {

        Long medicPlanId = medicPlanSignDto.getId();
        Long userId = loginAuthDto.getUserId();

        // 查询用药计划
        OmcMedicPlan omcMedicPlanQuery = omcMedicPlanMapper.selectByPrimaryKey(medicPlanId);
        if (omcMedicPlanQuery == null) {
            // 用药计划不存在
            throw new OmcBizException(ErrorCodeEnum.OMC10038004);
        }

        // 提交计划者才可以确认
        if (!omcMedicPlanQuery.getCreatorId().equals(userId)) {
            // 无法确认
            throw new OmcBizException(ErrorCodeEnum.OMC10038005);
        }

        String processInstanceId = omcMedicPlanQuery.getProcessInstanceId();
        Task task = taskService.createTaskQuery()
                .taskTenantId(loginAuthDto.getGroupId().toString())
                .processDefinitionKey(MedicConstant.PROCESS_KEY_MEDIC_PLAN)
                .taskAssignee(userId.toString())
                .processInstanceId(processInstanceId)
                .taskDefinitionKey(MedicConstant.MEDIC_PLAN_TASK_SIGN)
                .singleResult();

        if (task == null) {
            // 任务不存在
            throw new OmcBizException(ErrorCodeEnum.OMC10038003);
        }

        String comment = MedicConstant.MEDIC_PLAN_COMMENT_SIGN;
        Integer state = MedicConstant.MEDIC_PLAN_STATE_SIGN;

        // 设置用户id
        Authentication.setAuthenticatedUserId(loginAuthDto.getUserName() + "[班长]");
        // 添加批注信息
        taskService.addComment(task.getId(), processInstanceId, comment);
        // 完成任务
        taskService.complete(task.getId());

        OmcMedicPlan omcMedicPlan = new OmcMedicPlan();
        omcMedicPlan.setId(medicPlanId);
        omcMedicPlan.setUpdateInfo(loginAuthDto);
        omcMedicPlan.setPictureId(medicPlanSignDto.getPictureId());
        omcMedicPlan.setState(state);

        Integer result = omcMedicPlanMapper.updateByPrimaryKeySelective(omcMedicPlan);
        if (result < 1) {
            // 家属签字失败
            throw new OmcBizException(ErrorCodeEnum.OMC10038007);
        }

        // 生成用药记录
        String date = omcMedicPlanQuery.getBeginDate();
        do {
            int index_hour = MedicConstant.MEDIC_INDEX_HOUR;
            int start_hour = 0;
            int end_hour = 0;
            int day_hour = MedicConstant.MEDIC_HOUR_DAY;
            int duration = day_hour / omcMedicPlanQuery.getUsages();
            for (int i = 1; i <= omcMedicPlanQuery.getUsages(); i++) {
                start_hour = index_hour + (i - 1) * duration;
                end_hour = start_hour + duration;
                String str_start_hour = "";
                String str_end_hour = "";
                if (start_hour < 10) {
                    str_start_hour = "0" + start_hour;
                } else {
                    str_start_hour = "" + start_hour;
                }
                if (end_hour < 10) {
                    str_end_hour = "0" + end_hour;
                } else {
                    str_end_hour = "" + end_hour;
                }
                String startMedic = date + "T" + str_start_hour + ":" + "00" + ":" + "05";
                String endMedic = date + "T" + str_end_hour + ":" + "00" + ":"  + "00";
                log.info("# start medic = {}, end medic = {}", startMedic, endMedic);
                OmcMedicRecord omcMedicRecord = new OmcMedicRecord();
                omcMedicRecord.setMedicPlanId(medicPlanId);
                omcMedicRecord.setDate(date);
                omcMedicRecord.setTimeSlice(str_start_hour + ":" + "00" + ":" + "00 -- " + str_end_hour + ":" + "00" + ":"  + "00");
                omcMedicRecord.setUserName(loginAuthDto.getUserName());
                omcMedicRecord.setGroupId(loginAuthDto.getGroupId());
                omcMedicRecord.setNursingGroupId(omcMedicPlanQuery.getNursingGroupId());
                omcMedicRecord.setUpdateInfo(loginAuthDto);

                // 调用子流程  -- 用药记录流程
                // 启动请假申请流程
                Map<String,Object> recordVariables = new HashMap<String,Object>();
                recordVariables.put(MedicConstant.VAR_MEDIC_RECORD_START_MEDIC, startMedic);
                recordVariables.put(MedicConstant.VAR_MEDIC_RECORD_END_MEDIC, endMedic);
                recordVariables.put(MedicConstant.VAR_MEDIC_RECORD_NURSING_GROUP_ID, omcMedicPlanQuery.getNursingGroupId().toString());
                recordVariables.put(MedicConstant.VAR_MEDIC_RECORD_MONITOR, loginAuthDto.getUserId().toString());

                // 启动流程  带TenantId
                ProcessInstance pi = omcActivitiService.startProcessInstanceByKeyAndTenantId(MedicConstant.PROCESS_KEY_MEDIC_RECORD,
                        recordVariables, loginAuthDto.getGroupId());
                // 根据流程实例Id查询任务
                Task recordTask = taskService.createTaskQuery().processInstanceId(pi.getProcessInstanceId()).singleResult();

                // 获取流程实例id
                processInstanceId = recordTask.getProcessInstanceId();
                // 设置用户id()
                Authentication.setAuthenticatedUserId(loginAuthDto.getUserName() + "[班长]");
                // 添加批注信息
                taskService.addComment(recordTask.getId(), processInstanceId, MedicConstant.MEDIC_RECORD_COMMENT_APPLY);

                omcMedicRecord.setProcessInstanceId(pi.getProcessInstanceId());
                omcMedicRecord.setState(MedicConstant.MEDIC_RECORD_STATE_COMMIT);

                omcMedicRecordService.save(omcMedicRecord);
            }
            date = DateUtil.dateToStr(DateUtil.dateAddDay(DateUtil.stringToDate(date), 1));
        } while (date.compareTo(omcMedicPlanQuery.getEndDate()) <= 0);

        return result;
    }

    /**
     * medic plan modify
     *
     * @param medicPlanDto the medic plan dto
     * @param loginAuthDto the login auth dto
     *
     * @return the int.
     */
    @Override
    public Integer modify(MedicPlanDto medicPlanDto, LoginAuthDto loginAuthDto) {

        Long medicPlanId = medicPlanDto.getId();
        Long userId = loginAuthDto.getUserId();

        Preconditions.checkArgument(medicPlanId != null,
                cmnyMessageSource.getMessage("medic.plan.id.null", null));

        // 查询用药计划
        OmcMedicPlan omcMedicPlanQuery = omcMedicPlanMapper.selectByPrimaryKey(medicPlanId);
        if (omcMedicPlanQuery == null) {
            // 用药计划不存在
            throw new OmcBizException(ErrorCodeEnum.OMC10038004);
        }

        String beginDate = omcMedicPlanQuery.getBeginDate();
        String endDate = omcMedicPlanQuery.getEndDate();

        // 校验日期格式
        if (PublicUtil.isNotEmpty(medicPlanDto.getBeginDate())
                && !medicPlanDto.getBeginDate().equals(omcMedicPlanQuery.getBeginDate())) {
            // 校验时间格式
            Preconditions.checkArgument(PubUtils.is_YYY_MM_DD(medicPlanDto.getBeginDate()),
                    cmnyMessageSource.getMessage("medic.plan.begin.date.error", null));

            omcMedicPlanQuery.setBeginDate(medicPlanDto.getBeginDate());
        }

        // 校验日期格式
        if (PublicUtil.isNotEmpty(medicPlanDto.getEndDate())
                && !medicPlanDto.getEndDate().equals(omcMedicPlanQuery.getEndDate())) {
            // 校验时间格式
            Preconditions.checkArgument(PubUtils.is_YYY_MM_DD(medicPlanDto.getEndDate()),
                    cmnyMessageSource.getMessage("medic.plan.end.date.error", null));

            omcMedicPlanQuery.setEndDate(medicPlanDto.getEndDate());
        }

        // 校验结束时间是否大于开始时间
        Preconditions.checkArgument(omcMedicPlanQuery.getEndDate()
                        .compareTo(omcMedicPlanQuery.getBeginDate()) >= 0,
                cmnyMessageSource.getMessage("medic.plan.end.compare.begin.date.error", null));

        if (PublicUtil.isNotEmpty(medicPlanDto.getDrug())) {
            omcMedicPlanQuery.setDrug(medicPlanDto.getDrug());
        }

        if (PublicUtil.isNotEmpty(medicPlanDto.getNumber())) {
            omcMedicPlanQuery.setNumber(medicPlanDto.getNumber());
        }

        if (PublicUtil.isNotEmpty(medicPlanDto.getStandard())) {
            omcMedicPlanQuery.setStandard(medicPlanDto.getStandard());
        }

        if (PublicUtil.isNotEmpty(medicPlanDto.getUsages())) {
            omcMedicPlanQuery.setUsages(medicPlanDto.getUsages());
        }
        if (PublicUtil.isNotEmpty(medicPlanDto.getRemark())) {
            omcMedicPlanQuery.setRemark(medicPlanDto.getRemark());
        }

        // 提交计划者才可以确认
        if (!omcMedicPlanQuery.getCreatorId().equals(userId)) {
            // 无法确认
            throw new OmcBizException(ErrorCodeEnum.OMC10038005);
        }

        // 校验老人Id
        if (medicPlanDto.getOldmanId() != null
                && medicPlanDto.getOldmanId().equals(omcMedicPlanQuery.getOldmanId())) {
            // 判断老人是否为该班组
            OldmanBedRoomBuildingVo obrbv = oldmanService.queryOldmanBedRoomBuildingByOldmanId(
                    medicPlanDto.getOldmanId().intValue());

            if (obrbv == null) {
                throw new OmcBizException(ErrorCodeEnum.OMC10038002);
            }

            // 校验老人是否为该班组
            OmcNursingRoomBind omcNursingRoomBind = new OmcNursingRoomBind();
            omcNursingRoomBind.setNursingGroupId(omcMedicPlanQuery.getNursingGroupId());
            omcNursingRoomBind.setRoomId((long) obrbv.getRoomId());
            int count = omcNursingRoomBindMapper.selectCount(omcNursingRoomBind);
            if (count < 1) {
                // 该老人不属于该班组
                throw new OmcBizException(ErrorCodeEnum.OMC10038006);
            }

            omcMedicPlanQuery.setOldmanName(obrbv.getOldmanName());
        }

        String processInstanceId = omcMedicPlanQuery.getProcessInstanceId();
        Task task = taskService.createTaskQuery()
                .taskTenantId(loginAuthDto.getGroupId().toString())
                .processDefinitionKey(MedicConstant.PROCESS_KEY_MEDIC_PLAN)
                .taskAssignee(userId.toString())
                .processInstanceId(processInstanceId)
                .taskDefinitionKey(MedicConstant.MEDIC_PLAN_TASK_APPLY)
                .singleResult();

        // 调整该用药计划
        String comment = MedicConstant.MEDIC_PLAN_COMMENT_MODIFY;
        Integer state = MedicConstant.MEDIC_PLAN_STATE_APPLY;

        if (task == null) {
            // 已经审批完成的用药计划 - 有可能是终止之前的用药计划

            // 用药计划不能为空
            Preconditions.checkArgument(PublicUtil.isNotEmpty(medicPlanDto.getBeginDate()),
                    cmnyMessageSource.getMessage("medic.plan.begin.date.null", null));

            // 校验时间格式
            Preconditions.checkArgument(PubUtils.is_YYY_MM_DD(medicPlanDto.getBeginDate()),
                    cmnyMessageSource.getMessage("medic.plan.begin.date.error", null));

            // 用药计划不能早于之前的用药计划
            Preconditions.checkArgument(beginDate.compareTo(medicPlanDto.getBeginDate()) < 0,
                    cmnyMessageSource.getMessage("medic.plan.begin.date.compare.last.error", null));

            // 用药计划不能早于今天
            Preconditions.checkArgument(DateUtil.dateToStr(new Date()).compareTo(medicPlanDto.getBeginDate()) < 0,
                    cmnyMessageSource.getMessage("medic.plan.begin.date.compare.today.error", null));

            // 判断是否需要终止老的用药计划
            if (endDate.compareTo(medicPlanDto.getBeginDate()) < 0) {
                // 新的用药计划晚于老的用药计划结束时间 -- 不用终止计划
            } else {
                // 终止计划
                OmcMedicPlan omcMedicPlan = new OmcMedicPlan();
                omcMedicPlan.setId(medicPlanId);
                omcMedicPlan.setEndDate(DateUtil.dateToStr(DateUtil.dateAddDay(DateUtil.stringToDate(medicPlanDto.getBeginDate()), -1)));
                omcMedicPlanMapper.updateByPrimaryKeySelective(omcMedicPlan);

                // 新计划的下一天到老计划的结束日期
                List<OmcMedicRecord> medicRecordList = omcMedicRecordService
                        .queryMedicRecordListByPlanIdAndBeginDate(medicPlanId, medicPlanDto.getBeginDate());
                for (OmcMedicRecord medicRecord : medicRecordList) {
                    // 终止用药记录
                    runtimeService.deleteProcessInstance(medicRecord.getProcessInstanceId(), "用药计划修改.");
                    omcMedicRecordService.deleteByKey(medicRecord.getId());
                }
            }

            // 新增用药计划
            omcMedicPlanQuery.setUpdateInfo(loginAuthDto);
            omcMedicPlanQuery.setState(state);

            // 执行流程
            Map<String, Object> variables = new HashMap<String, Object>();
            variables.put(MedicConstant.VAR_MEDIC_PLAN_USER_ID, loginAuthDto.getUserId().toString());

            ProcessInstance processInstance = omcActivitiService
                    .startProcessInstanceByKeyAndTenantId(MedicConstant.PROCESS_KEY_MEDIC_PLAN,
                            variables, loginAuthDto.getGroupId());

            // 查询当前任务
            task = omcActivitiService.getTaskByProcessInstanceId(processInstance.getProcessInstanceId());

            // 添加批注
            omcActivitiService.addTaskComment(task, loginAuthDto.getUserName() + "[班长]", "提交申请");

            // 完成下单
            taskService.complete(task.getId());

            omcMedicPlanQuery.setId(null);
            omcMedicPlanQuery.setProcessInstanceId(processInstance.getProcessInstanceId());
            omcMedicPlanQuery.setGroupId(loginAuthDto.getGroupId());
            omcMedicPlanQuery.setUpdateInfo(loginAuthDto);
            omcMedicPlanQuery.setState(MedicConstant.MEDIC_PLAN_STATE_APPLY);

            return omcMedicPlanMapper.insertSelective(omcMedicPlanQuery);
        } else {
            // 设置用户id
            Authentication.setAuthenticatedUserId(loginAuthDto.getUserName() + "[班长]");
            // 添加批注信息
            taskService.addComment(task.getId(), processInstanceId, comment);
            // 完成任务
            taskService.complete(task.getId());

            omcMedicPlanQuery.setUpdateInfo(loginAuthDto);
            omcMedicPlanQuery.setState(state);

            return omcMedicPlanMapper.updateByPrimaryKeySelective(omcMedicPlanQuery);
        }
    }
}
